package com.bjpowernode.mvc.controller;

import com.bjpowernode.db.domain.Recharge;
import com.bjpowernode.mvc.convert.RechargeConvert;
import com.bjpowernode.mvc.model.result.CommonResult;
import com.bjpowernode.mvc.model.vo.RechargeVO;
import com.bjpowernode.mvc.service.inter.RechargeService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RequiredArgsConstructor
@RestController
public class RechargeController {

    private final RechargeService rechargeService;

    private final RechargeConvert rechargeConvert;

    @GetMapping("/recharge/info")
    public CommonResult queryRechargeInfo(
            @RequestHeader("uid") Integer uid,
            @RequestParam Integer pageNo,
            @RequestParam Integer pageSize
    ) {

        //1、检查参数
        pageNo = (pageNo == null || pageNo < 1) ? 1 : pageNo;
        pageSize = (pageSize == null || pageSize < 1 || pageSize > 100) ? 6 : pageSize;


        //2、查询最近充值记录
        List<Recharge> rechargeResultList = rechargeService.queryRechargeByUid(uid, pageNo, pageSize);

        //3、转VO
        List<RechargeVO> rechargeResultVOList = rechargeConvert.convertRechargeVOList(rechargeResultList);
        return CommonResult.ok(rechargeResultVOList);
    }


}
